/**
author: sailing
date: 2016/11/17
fun： 获取数据去画topo
***/
import fetchJson from './fetchJson'
import tools from './tools'
import data from './data'
import eventBus from '../eventBus'
export default {
  start (vm) {
    this.vm = vm
    if (data.s_select && data.e_select) {
      this.getPoint()
    } else {
      eventBus.bus.$message({
        message: '请选择两个端口!',
        type: 'warning'
      })
    }
  },
  getPoint (id, cy) {
    this.cy = cy
    var url = tools.mergeUrl('/topology/getport/')
    fetchJson.getJson({
      self: this,
      url: url + '?id1=' + data.s_select.data.id + '&id2=' + data.e_select.data.id,
      callback: this.callback,
      error: this.error
    })
  },
  callback (data) {
    if (data.edges.length > 0) {
      eventBus.bus.$emit('startWin')
      eventBus.bus.$emit('drawLine', data)
    } else {
      eventBus.bus.$message({
        message: '设备之间没有物理连线!',
        type: 'warning'
      })
    } 
  },
  error () {
  }
}
